package com.cat.enumerate;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/reordered-power-of-2/?envType=problem-list-v2&envId=enumerationhttps://leetcode.cn/problems/reordered-power-of-2/?envType=problem-list-v2&envId=enumeration
 * @create 2025/9/20 19:20
 * @since JDK17
 */

public class Solution03 {
    static Set<String> set = new HashSet<>();
    static {    // 将所有2的幂加入set中
        for (int i = 0; i < 31; i++) {
            String s = String.valueOf(1 << i);
            char[] array = s.toCharArray();
            Arrays.sort(array);
            set.add(new String(array));
        }
    }
    public boolean reorderedPowerOf2(int n) {
        String s = String.valueOf(n);
        char[] array = s.toCharArray();
        return set.contains(new String(array));
    }
}
